<template>
	<view>
		<cu-custom bgColor="bg-maincolor" :isBack="true">
			<block slot="content">
				企业申请
			</block>
		</cu-custom>
		<view>
			<view class="apply_boxone">
				<view>企业资料</view>
			</view>
			<view class="apply_box flex">
				<view class="con_text">名称</view>
				<input class="con_infom" placeholder="请输入公司名称" v-model="company_name" />
			</view>
			<view class="apply_box flex">
				<view class="con_text">联系方式</view>
				<input class="con_infom" placeholder="请输入电话号码" v-model="phone">
			</view>
			<view class="apply_box flex">
				<view class="con_text">联系人</view>
				<input class="con_infom" placeholder="请输入联系人姓名" v-model="contacts" />
			</view>
			<view class="apply_box flex" style="border-bottom-width:0">
				<view class="con_text">地址</view>
				<input class="con_infom" placeholder="请输入公司地址" v-model="address" />
				<!-- <view v-if="res.result" class="con_infom">{{apply_list.address}}</view> -->
			</view>
		</view>
		<view class="cu-bar tabbar bg-white foot" v-if="applist==null">
			<button class="cancel_but">取消</button>
			<button class="submit_but" @tap="handsubmit()">提交</button>	
		</view>
		<view class="cu-bar tabbar bg-white foot" v-if="applist">
			<view class="msgTextBox">
				<text class="msgText">您正在申请，请耐心等待!</text>
			</view>
		</view>
	</view>
</template>

<script>
	const {
		appLogin,
		httpGet,
		httpPost
	} = require("@/utils/common.js")
	export default {
		data() {
			return {
				company_name: '',
				phone: '',
				contacts: '',
				address: '',
				applist: [],
				msg: '',
			}
		},
		onLoad() {
			appLogin((user_info) => {
				console.log(user_info)
				this.get_information()
			})
		},
		methods: {
			handsubmit() {
				var data = {
					company_name: this.company_name,
					phone: this.phone,
					contacts: this.contacts,
					address: this.address
				}
				if (!this.company_name) {
					uni.showToast({
						title: '请填公司名称',
						icon: 'none',
					});
					return;
				}
				if (!this.phone) {
					uni.showToast({
						title: '请填公司电话',
						icon: 'none',
					});
					return;
				}
				if (!this.contacts) {
					uni.showToast({
						title: '请填写联系人姓名',
						icon: 'none',
					});
					return;
				}
				if (!this.address) {
					uni.showToast({
						title: '请填公司地址',
						icon: 'none',
					});
					return;
				}
				httpPost({
					url: '/api/company/apply',
					data: data
				}).then(res => {
					console.log(res,5555)
					this.get_information()
				})
			},
			get_information() {
				httpGet({
					url: '/api/company/apply_info',
				}).then((res) => {
					console.log(res,555)
					this.applist = res.result
					if(res.result){
						this.company_name = res.result.company_name
						this.phone= res.result.phone
						this.address = res.result.address
						this.contacts = res.result.contacts
					}
				})
			}
		}
	}
</script>

<style>
	.apply_boxone {
		height: 90rpx;
		line-height: 90rpx;
		background-color: #efefef;
		font-size: 30rpx;
		padding-left: 38rpx;
		color: #333333;
	}

	.apply_box {
		height: 90rpx;
		line-height: 90rpx;
		padding-left: 38rpx;
		background-color: #FFFFFF;
		border-width: 2rpx;
		border-bottom-style: solid;
		border-color: #e6e6e6;
	}

	.con_text {
		color: #989898;
		font-size: 30rpx;
	}

	.con_infom {
		position: absolute;
		right: 35rpx;
		color: #333333;
		font-size: 30rpx;
		text-align: right;
		line-height: 90rpx;
		height: 90rpx;
		width: 750rpx;
	}

	.cancel_but {
		border-radius: 90rpx;
		border-width: 1rpx;
		border-style: solid;
		border-color: #3b73f6;
		text-align: center;
		height: 80rpx;
		width: 335rpx;
		line-height: 80rpx;
		color: #3b73f6;
		font-size: 30rpx;
	}

	.submit_but {
		border-radius: 90rpx;
		border-width: 1rpx;
		border-style: solid;
		background-color: #3b73f6;
		text-align: center;
		height: 80rpx;
		width: 335rpx;
		line-height: 80rpx;
		color: #FFFFFF;
		font-size: 30rpx;
	}
	
	.msgText{
		font-size: 30rpx;
	}
	
	.msgTextBox{
		text-align: center;
		width: 100%;
	}
</style>
